package com.hnucm.cooklife.model;

import com.hnucm.cooklife.base.BaseModel;
import com.hnucm.cooklife.bean.db.OrderDetail;
import com.hnucm.cooklife.bean.order.OrderDetailData;
import com.hnucm.cooklife.contract.OrderDetaildetail.Contract;

import java.util.List;

import io.reactivex.Observable;

public class OrderDetailModel extends BaseModel implements Contract.IOrderDetailModel {
    @Override
    public Observable<OrderDetail> loadOrderDetail(Integer oId) {
        return mApiServer.loadOrderDetail(oId)
                .map(orderDetailData -> {
                    OrderDetailData.DataDTO dto = orderDetailData.getData();
                    OrderDetail orderDetail = new OrderDetail();
                    orderDetail.oId = dto.getoId();
                    orderDetail.ocap = dto.getOcap();
                    orderDetail.ocato = dto.getOcato();
                    orderDetail.osold = dto.getOsold();
                    orderDetail.oname = dto.getOname();
                    orderDetail.oprice = dto.getOprice();
                    orderDetail.ofrom = dto.getOfrom();
                    orderDetail.oto = dto.getOto();
                    orderDetail.ogroupId = dto.getOgroupId();
                    orderDetail.orderpicList.addAll(dto.getOrderpicList());
                    return orderDetail;
                });
    }

    @Override
    public Observable<OrderDetail> refreshOrderDetail(Integer oId) {
        return loadOrderDetail(oId);
    }
}
